<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('pocAutoConfig列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>批次类型：</p>
                                <input type="type" name="type"/>
                            </li>
                            <li>
                                <p>自动发送：</p>
                                <select name="autoEnable" th:with="type=${@dict.getType('auto_enable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>所属系统：</p>
                                <input type="text" name="sys"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" >
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                    <i class="fa fa-remove"></i> 删除
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = '';
        var removeFlag = '';
        var prefix = ctx + "wx/sendAutoConfig";
        var autoEnable = [[${@dict.getType('auto_enable')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "发送配置",
                sortName: "id",
                sortOrder: "asc",
                showToggle: false,
                showColumns: false,
                showSearch: false,
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '主键',
                    visible: false
                },
                {
                    field : 'type', 
                    title : '批次类型',
                    sortable: true
                },
                {
                    field : 'autoEnable', 
                    title : '自动发送',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field : 'sys', 
                    title : '所属系统',
                    sortable: true
                },
                {
                    field : 'typeDesc', 
                    title : '描述'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 独立状态显示 */
        function statusTools(row) {
            if (row.autoEnable == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 关 */
        function disable(id) {
            $.modal.confirm("确认关闭该类型的自动发送吗？", function() {
                console.log({ "id": id, "autoEnable": "1" });
                $.operate.post(prefix +"/edit/", { "id": id, "autoEnable": "1" });
            })
        }

        /* 开 */
        function enable(id) {
            $.modal.confirm("确认开启该类型的自动发送吗？", function() {
                console.log({ "id": id, "autoEnable": "1" });
                $.operate.post(prefix + "/edit/", { "id": id, "autoEnable": "0" });
            })
        }
    </script>
</body>
</html>